package com.glodon.paas.util;

import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

import org.apache.commons.lang.StringUtils;

import com.glodon.paas.consts.StringConst;

public class PropertyUtil {

	public static Map<String, String> convertFileToMap(String fileName) {
		Map<String, String> infoMap = new HashMap<String, String>();
		if(StringUtils.isEmpty(fileName)){
			return infoMap;
		}
		Properties properties = new Properties();
		
		InputStream is = PropertyUtil.class.getResourceAsStream("/"+fileName+".properties");
		try {
			if (is != null) {
				properties.load(is);
				Object[] keys = (Object[])properties.keySet().toArray();
				for (Object key : keys) {
					String value = properties.getProperty((String)key);
					if(value!=null){
						value = new String(value.getBytes(StringConst.ISO88591),StringConst.UTF8);
					}
					infoMap.put((String)key, value);
				}
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
		return infoMap;
	}
	
	

}
